package org.scohen.juploadr.uploadapi.zooomr.photosets;

import java.util.SortedMap;
import java.util.TreeMap;

import org.scohen.juploadr.app.PhotoSet;
import org.scohen.juploadr.app.UploadImage;
import org.scohen.juploadr.uploadapi.zooomr.DefaultZooomrHandler;
import org.scohen.juploadr.uploadapi.zooomr.PostUploadAction;
import org.scohen.juploadr.uploadapi.zooomr.ZooomrMethod;
import org.scohen.juploadr.uploadapi.zooomr.ZooomrRestApi;

public class AddPhoto extends ZooomrMethod implements PostUploadAction {
    private PhotoSet toAddTo;
    private String photoId;
    private UploadImage image;

    public AddPhoto(PhotoSet toAddTo, UploadImage img) {
        this.toAddTo = toAddTo;
        this.image = img;
        this.photoId = img.getPhotoId();

    }

    public DefaultZooomrHandler getResponseHandler() {
        return new AddPhotoHandler(this);
    }

    public SortedMap<String, String> getParams() {
        SortedMap<String, String> params = new TreeMap<String, String>();
       	params.put("method", "zooomr.photosets.addPhoto");
        params.put("api_key", ZooomrRestApi.ZOOOMR_API_KEY);
        params.put("photoset_id", toAddTo.getId());
        params.put("photo_id", photoId);
        return params;
    }

    public boolean isAuthorized() {
        return true;
    }

    public String getErrorText() {
        return "add " + image.getTitle() + " to photoset " + toAddTo.getTitle();
    }

}
